package com.jyu.sati.business.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jyu.sati.business.service.TechRequireService;
import com.jyu.sati.business.service.TechSupplyService;
import com.jyu.sati.common.util.AjaxResult;
import com.jyu.sati.entity.TechSupplyInfo;
import com.jyu.sati.vo.DockingVo;

/**
 * 供需对接控制器
 * 
 * @author 淋雨又调皮
 *
 */
@RequestMapping("/docking")
@Controller
public class DockingController extends BaseController {
	@Autowired
	private TechRequireService trService;
	@Autowired
	private TechSupplyService tsService;

	/**
	 * 匹配相应的技术需求或技术供给
	 * 
	 * @param techId
	 *            技术供需id
	 * @param techInfoType
	 *            技术供需信息类型 ：1是需求,2是供给
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/getDockingInfo", method = { RequestMethod.POST })
	public AjaxResult getDockingInfo(@RequestBody DockingVo vo) {
		AjaxResult result = getAjaxResult();
		try {
			if (vo.getTechInfoType() == null && vo.getTechId() == null) {
				return getFailedRusult(result, "传入参数不能为空！");
			}
			if (vo.getTechInfoType() == DockingVo.TECHINFO_TYPE_REQUIRE) {
				// 根据需求匹配供给信息
				result = getSuccessRusult(result, "对接成功！", tsService.getTechSupPageInfoByTechReqId(vo.getTechId()));
			} else if (vo.getTechInfoType() == DockingVo.TECHINFO_TYPE_SUPPLY) {
				// 根据供给匹配需求信息
				result = getSuccessRusult(result, "对接成功！", trService.getTechRepPageInfoByTechSupId(vo.getTechId()));
			}
		} catch (Exception e) {
			result = getFailedRusult(result, "对接失败！");
		}
		return result;
	}

	/**
	 * 根据技术供给匹配后的技术需求信息分页
	 * 
	 * @param key1
	 * @param key1
	 * @param key1
	 * @param pageSize
	 * @param pageNo
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/getRequireDockingInfo", method = { RequestMethod.POST })
	public AjaxResult getRequireDockingInfo(@RequestBody DockingVo condition) {
		AjaxResult result = getAjaxResult();
		try {
			result = getSuccessRusult(result, "对接成功！", trService.getTechReqPageByKeys(condition));
		} catch (Exception e) {
			result = getFailedRusult(result, "对接失败！");
		}
		return result;
	}

	/**
	 * 根据技术需求匹配后的技术供给信息分页
	 * 
	 * @param key1
	 * @param key1
	 * @param key1
	 * @param pageSize
	 * @param pageNo
	 * @returnO
	 */
	@ResponseBody
	@RequestMapping(value = "/getSupplyDockingInfo", method = { RequestMethod.POST })
	public AjaxResult getSupplyDockingInfo(@RequestBody DockingVo condition) {
		AjaxResult result = getAjaxResult();
		try {
			result = getSuccessRusult(result, "对接成功！", tsService.getTechSuppplyPageByKeys(condition));
		} catch (Exception e) {
			result = getFailedRusult(result, "对接失败！");
		}
		return result;
	}

}
